/**
 * Created by wlc on 2018/3/28.
 */

/**
 * 全局变量
 */
//溶质
var SoluteArr;
var SolutesArr;

//溶剂
var SolventArr;
var SolventsArr;

//通知栏
var notyf;


/**
 * 变量,对象,表单初始化
 */
window.onload = function () {
    //溶质
    SolutesArr = new Array();
    $('.Solute').attr("disabled", "");

    //溶剂
    SolventsArr = new Array();
    $('.Solvent').attr("disabled", "");

    //文件
    $('#Block_information').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['frg'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            feedback2: "files were chosen",
            drop: "Drop file here to Upload",
            removeConfirmation: "Are you sure you want to remove this file?",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only frg are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#Active_track_input').filer({
        limit: 1,
        maxSize: 3,
        extensions: ['txt'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            feedback2: "files were chosen",
            drop: "Drop file here to Upload",
            removeConfirmation: "Are you sure you want to remove this file?",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Text are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#Optimize_the_structure').filer({
        limit: 1,
        maxSize: 3,
        extensions: ['jpg', 'jpeg', 'png', 'gif'],
        changeInput: true,
        showThumbs: true,
        captions: {
            button: "上传",
            feedback: "",
            feedback2: "files were chosen",
            drop: "Drop file here to Upload",
            removeConfirmation: "Are you sure you want to remove this file?",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only jpg/jpeg/png/gif are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#QM_out1').filer({
        limit: 1,
        maxSize: 3,
        extensions: ['txt'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            feedback2: "files were chosen",
            drop: "Drop file here to Upload",
            removeConfirmation: "Are you sure you want to remove this file?",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Text are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#QM_out2').filer({
        limit: 1,
        maxSize: 3,
        extensions: ['txt'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            feedback2: "files were chosen",
            drop: "Drop file here to Upload",
            removeConfirmation: "Are you sure you want to remove this file?",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Text are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#ESP').filer({
        limit: 1,
        maxSize: 3,
        extensions: ['jpg', 'jpeg', 'png', 'gif'],
        changeInput: true,
        showThumbs: true,
        captions: {
            button: "上传",
            feedback: "",
            feedback2: "files were chosen",
            drop: "Drop file here to Upload",
            removeConfirmation: "Are you sure you want to remove this file?",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only jpg/jpeg/png/gif are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gaussFiles_log').filer({
        limit: 300,
        maxSize: 2048,
        extensions: ['log'],
        changeInput: true,
        showThumbs: true,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Log are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gaussFiles_dat').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['dat'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Dat are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gebfFiles_keys').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['keys'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only keys are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gebfFiles_cha').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['cha'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only cha are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gebfFiles_txt').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['txt'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only txt are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gebfFiles_log').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['log'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Log are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#gebfFiles_frg').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['frg'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only frg are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#dmol3Files_cif').filer({
        limit: 300,
        maxSize: 2048,
        extensions: ['cif'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only cif are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#dmol3Files_outmol').filer({
        limit: 300,
        maxSize: 2048,
        extensions: ['outmol'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only outmol are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#dmol3Files_dosOutmol').filer({
        limit: 300,
        maxSize: 2048,
        extensions: ['outmol'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only outmol are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#dmol3Files_bandStrOutmol').filer({
        limit: 300,
        maxSize: 2048,
        extensions: ['outmol'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only outmol are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#castepFiles_cif').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['cif'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only cif are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#castepFiles_castep').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['castep'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only castep are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#castepFiles_dosCastep').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['castep'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only castep are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#castepFiles_bandStrCastep').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['castep'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only castep are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_CONTCAR').filer({
        limit: 1,
        maxSize: 100,
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only cha are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_INCAR').filer({
        limit: 1,
        maxSize: 100,
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only txt are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_KPOINTS').filer({
        limit: 1,
        maxSize: 100,
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Log are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_OUTCAR').filer({
        limit: 1,
        maxSize: 100,
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Log are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_POSCAR').filer({
        limit: 1,
        maxSize: 100,
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only cha are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_POSCARcif').filer({
        limit: 1,
        maxSize: 100,
        extensions: ['cif'],
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only cif are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });
    $('#vaspFiles_POTCAR').filer({
        limit: 1,
        maxSize: 100,
        changeInput: true,
        showThumbs: false,
        captions: {
            button: "上传",
            feedback: "",
            errors: {
                filesLimit: "Only {{fi-limit}} files are allowed to be uploaded.",
                filesType: "Only Log are allowed to be uploaded.",
                filesSize: "{{fi-name}} is too large! Please upload file up to {{fi-maxSize}} MB.",
                filesSizeAll: "Files you've choosed are too large! Please upload files up to {{fi-maxSize}} MB."
            }
        }
    });

    //通知栏
    notyf = new Notyf();

    //PBC
    $('#Lattice_parameters_length').attr("disabled", "");
    $('#Lattice_parameters_angle').attr("disabled", "");
    $('#Space_group').attr("disabled", "");

    //Slab
    $('.Slab').attr("disabled", "");

    //Statistics
    $('.Statistics').attr("disabled", "");
};

/**
 * 表格初始化
 */
//Crystal_table
Crystal_table = [
    ['', ''],
    ['', ''],
    ['', ''],
    ['', ''],
    ['', ''],
    ['', ''],
    ['', '']
];
$('#Crystal_table').jexcel({
    data: Crystal_table,
    colHeaders: ['原子', '数目'],
    colWidths: [200, 200],
//        columns: [
//            { type: 'dropdown', source:['Seat', 'Renault', 'Peugeot', 'Dacia', 'Citroen', 'Opel', 'Alfa Romeo', 'Škoda', 'Chevrolet', 'Porsche', 'Honda', 'Subaru', 'Mazda', 'Mitsubishi', 'Lexus', 'Toyota', 'BMW', 'Volkswagen', 'Suzuki', 'Mercedes-Benz', 'Saab', 'Audi', 'Kia', 'Land Rover', 'Dodge', 'Chrysler', 'Ford', 'Hummer', 'Hyundai', 'Infiniti', 'Jaguar', 'Jeep', 'Nissan', 'Volvo', 'Daewoo', 'Fiat', 'MINI', 'Rover', 'Smart'] },
//            { type: 'dropdown', source:[{'id':1,'name':'Yellow'}, {'id':2,'name':'Black'}, {'id':3,'name':'Green'}] }
//        ]
});
//Slab_table
Slab_table = [
    ['', ''],
    ['', ''],
    ['', ''],
    ['', ''],
    ['', ''],
    ['', ''],
    ['', '']
];
$('#Slab_table').jexcel({
    data: Crystal_table,
    colHeaders: ['原子', '数目'],
    colWidths: [200, 200],
//        columns: [
//            { type: 'dropdown', source:['Seat', 'Renault', 'Peugeot', 'Dacia', 'Citroen', 'Opel', 'Alfa Romeo', 'Škoda', 'Chevrolet', 'Porsche', 'Honda', 'Subaru', 'Mazda', 'Mitsubishi', 'Lexus', 'Toyota', 'BMW', 'Volkswagen', 'Suzuki', 'Mercedes-Benz', 'Saab', 'Audi', 'Kia', 'Land Rover', 'Dodge', 'Chrysler', 'Ford', 'Hummer', 'Hyundai', 'Infiniti', 'Jaguar', 'Jeep', 'Nissan', 'Volvo', 'Daewoo', 'Fiat', 'MINI', 'Rover', 'Smart'] },
//            { type: 'dropdown', source:[{'id':1,'name':'Yellow'}, {'id':2,'name':'Black'}, {'id':3,'name':'Green'}] }
//        ]
});
// Calculate_base_set_table
Calculate_base_set_table = [
    ['', ''],
    ['', ''],
    ['', '']
];
$('#Calculate_base_set_table').jexcel({
    data: Calculate_base_set_table,
    colHeaders: ['基组', '原子类型'],
    colWidths: [300, 300],
//        columns: [
//            { type: 'dropdown', source:['Seat', 'Renault', 'Peugeot', 'Dacia', 'Citroen', 'Opel', 'Alfa Romeo', 'Škoda', 'Chevrolet', 'Porsche', 'Honda', 'Subaru', 'Mazda', 'Mitsubishi', 'Lexus', 'Toyota', 'BMW', 'Volkswagen', 'Suzuki', 'Mercedes-Benz', 'Saab', 'Audi', 'Kia', 'Land Rover', 'Dodge', 'Chrysler', 'Ford', 'Hummer', 'Hyundai', 'Infiniti', 'Jaguar', 'Jeep', 'Nissan', 'Volvo', 'Daewoo', 'Fiat', 'MINI', 'Rover', 'Smart'] },
//            { type: 'dropdown', source:[{'id':1,'name':'Yellow'}, {'id':2,'name':'Black'}, {'id':3,'name':'Green'}] }
//        ]
});
//optimization_table
optimization_table = [
    ['', '', '', '', '', '', ''],
    ['', '', '', '', '', '', ''],
    ['', '', '', '', '', '', '']
];
$('#optimization_table').jexcel({
    data: optimization_table,
    colHeaders: ['原子', 'X坐标', 'Y坐标', 'Z坐标', 'Mulliken', 'Natural', 'ESP'],
    colWidths: [50, 100, 100, 100, 80, 80, 80],
//        columns: [
//            { type: 'dropdown', source:['Seat', 'Renault', 'Peugeot', 'Dacia', 'Citroen', 'Opel', 'Alfa Romeo', 'Škoda', 'Chevrolet', 'Porsche', 'Honda', 'Subaru', 'Mazda', 'Mitsubishi', 'Lexus', 'Toyota', 'BMW', 'Volkswagen', 'Suzuki', 'Mercedes-Benz', 'Saab', 'Audi', 'Kia', 'Land Rover', 'Dodge', 'Chrysler', 'Ford', 'Hummer', 'Hyundai', 'Infiniti', 'Jaguar', 'Jeep', 'Nissan', 'Volvo', 'Daewoo', 'Fiat', 'MINI', 'Rover', 'Smart'] },
//            { type: 'dropdown', source:[{'id':1,'name':'Yellow'}, {'id':2,'name':'Black'}, {'id':3,'name':'Green'}] }
//        ]
});
//Vertical_Excited_State_table
Vertical_Excited_State_table = [
    ['', ''],
    ['', ''],
    ['', '']
];
$('#Vertical_Excited_State_table').jexcel({
    data: Vertical_Excited_State_table,
    colHeaders: ['激发能', '振子强度'],
    colWidths: [300, 300],
//        columns: [
//            { type: 'dropdown', source:['Seat', 'Renault', 'Peugeot', 'Dacia', 'Citroen', 'Opel', 'Alfa Romeo', 'Škoda', 'Chevrolet', 'Porsche', 'Honda', 'Subaru', 'Mazda', 'Mitsubishi', 'Lexus', 'Toyota', 'BMW', 'Volkswagen', 'Suzuki', 'Mercedes-Benz', 'Saab', 'Audi', 'Kia', 'Land Rover', 'Dodge', 'Chrysler', 'Ford', 'Hummer', 'Hyundai', 'Infiniti', 'Jaguar', 'Jeep', 'Nissan', 'Volvo', 'Daewoo', 'Fiat', 'MINI', 'Rover', 'Smart'] },
//            { type: 'dropdown', source:[{'id':1,'name':'Yellow'}, {'id':2,'name':'Black'}, {'id':3,'name':'Green'}] }
//        ]
});
//frequence_table
frequence_table = [
    [''],
    [''],
    ['']
];
$('#other_table').jexcel({
    data: frequence_table,
    colHeaders: ['频率'],
    colWidths: [100],
//        columns: [
//            { type: 'dropdown', source:['Seat', 'Renault', 'Peugeot', 'Dacia', 'Citroen', 'Opel', 'Alfa Romeo', 'Škoda', 'Chevrolet', 'Porsche', 'Honda', 'Subaru', 'Mazda', 'Mitsubishi', 'Lexus', 'Toyota', 'BMW', 'Volkswagen', 'Suzuki', 'Mercedes-Benz', 'Saab', 'Audi', 'Kia', 'Land Rover', 'Dodge', 'Chrysler', 'Ford', 'Hummer', 'Hyundai', 'Infiniti', 'Jaguar', 'Jeep', 'Nissan', 'Volvo', 'Daewoo', 'Fiat', 'MINI', 'Rover', 'Smart'] },
//            { type: 'dropdown', source:[{'id':1,'name':'Yellow'}, {'id':2,'name':'Black'}, {'id':3,'name':'Green'}] }
//        ]
});

/**
 *溶质对话框处理
 */
//Solute_modal_init
$('#Solute_modal').on('show.bs.modal', function (event) {
    var modal = $(this);
    var table = document.getElementById('Solute_t_element');
    var tbody = table.children[1];
    var childrenNum = tbody.children.length;
    for (var i = 0; i < childrenNum; i++) {
        tbody.removeChild(tbody.children[0]);
    }
    modal.find('.modal-body input').val("");
    SoluteArr = new Array(19);
});
$('#Solute_Elements_added').on('show.bs.modal', function (event) {
    var modal = $(this);
    modal.find('.modal-body input').val("");
});
//Solute_modal_process
$(document).on("click", '#Solute_modal .modal-footer .btn-primary', function (e) {
    var evt = e || window.event;               //保证兼容性
    var tar = evt.target || evt.srcElement;  //获取触发事件的元素

    if (SolutesArr.length !== 38) {
        var Charge = $('#Solute_modal .modal-body #Solute_Charge')[0].value;
        var multiplicity = $('#Solute_modal .modal-body #Solute_multiplicity')[0].value;
        var structure = $('#Solute_modal .modal-body #Solute_structure')[0].value;
        var SMILE_format = $('#Solute_modal .modal-body #Solute_SMILE_format')[0].value;
        var CAS = $('#Solute_modal .modal-body #Solute_CAS')[0].value;
        isEmpty(Charge) ? Charge = "null" : SoluteArr[14] = Charge;
        isEmpty(multiplicity) ? multiplicity = "null" : SoluteArr[15] = multiplicity;
        isEmpty(structure) ? structure = "null" : SoluteArr[16] = structure;
        isEmpty(SMILE_format) ? SMILE_format = "null" : SoluteArr[17] = SMILE_format;
        isEmpty(CAS) ? CAS = "null" : SoluteArr[18] = CAS;
        <!-- 存储数据 -->
        SolutesArr = SolutesArr.concat(SoluteArr);

        <!-- 创建表格一行 -->
        var table = document.getElementById('Solute_components');
        var tbody = table.children[1];
        var ele_num = 0;
        for (var i = 1; i <= 14; i = i + 2) {
            if (!isEmpty(SoluteArr[i])) {
                ele_num = ele_num + parseInt(SoluteArr[i]);
            }
        }
        var tr = document.createElement('tr');
        var td = document.createElement('td');
        var span = document.createElement('span');
        span.appendChild(document.createTextNode(SoluteArr.slice(0, 14).join("")));
        td.appendChild(span);
        tr.appendChild(td);
        var td = document.createElement('td');
        var span = document.createElement('span');
        span.appendChild(document.createTextNode(ele_num));
        td.appendChild(span);
        tr.appendChild(td);
        for (var j = 0; j < 2; j++) {
            var td = document.createElement('td');
            var span = document.createElement('span');
            span.appendChild(document.createTextNode(SoluteArr[j + 14]));
            td.appendChild(span);
            tr.appendChild(td);
        }
        var td = document.createElement('td');
        var span = document.createElement('span');
        span.appendChild(document.createTextNode(SoluteArr[18]));
        td.appendChild(span);
        tr.appendChild(td);
        tbody.appendChild(tr);
    } else {
        alert("溶质元素添加已满!");
    }
});
$(document).on("click", '#Solute_Elements_added .modal-footer .btn-primary', function (e) {
    var evt = e || window.event;               //保证兼容性
    var tar = evt.target || evt.srcElement;  //获取触发事件的元素

    var element = $('#Solute_Elements_added .modal-body #element')[0].value;
    var num = $('#Solute_Elements_added .modal-body #element_num')[0].value;
    var enough;
    for (var i = 0; i < 14; i = i + 2) {
        if (isEmpty(SoluteArr[i])) {
            if (!isEmpty(element) && !isEmpty(num)) {
                SoluteArr[i] = element;
                SoluteArr[i + 1] = num;
                <!-- 创建表格一行 -->
                var table = document.getElementById('Solute_t_element');
                var tbody = table.children[1];
                var tr = document.createElement('tr');
                for (var j = 0; j < 2; j++) {
                    var td = document.createElement('td');
                    var span = document.createElement('span');
                    span.appendChild(document.createTextNode(SoluteArr[i + j]));
                    td.appendChild(span);
                    tr.appendChild(td);
                }
                tbody.appendChild(tr);
            }
            enough = false;
            break;
        } else {
            enough = true;
        }
    }
    if (enough) {
        alert("能添加的元素已满！");
    }
});

/**
 *溶剂对话框处理
 */
//Solvent_modal_init
$('#Solvent_modal').on('show.bs.modal', function (event) {
    var modal = $(this);
    var table = document.getElementById('Solvent_t_element');
    var tbody = table.children[1];
    var childrenNum = tbody.children.length;
    for (var i = 0; i < childrenNum; i++) {
        tbody.removeChild(tbody.children[0]);
    }
    modal.find('.modal-body input').val("");
    SolventArr = new Array(11);
});
$('#Solvent_Elements_added').on('show.bs.modal', function (event) {
    var modal = $(this);
    modal.find('.modal-body input').val("");
});
//Solvent_modal_process
$(document).on("click", '#Solvent_modal .modal-footer .btn-primary', function (e) {
    var evt = e || window.event;               //保证兼容性
    var tar = evt.target || evt.srcElement;  //获取触发事件的元素

    if (SolventsArr.length !== 22) {
        var Charge = $('#Solvent_modal .modal-body #Solvent_Charge')[0].value;
        var multiplicity = $('#Solvent_modal .modal-body #Solvent_multiplicity')[0].value;
        var structure = $('#Solvent_modal .modal-body #Solvent_structure')[0].value;
        var SMILE_format = $('#Solvent_modal .modal-body #Solvent_SMILE_format')[0].value;
        var CAS = $('#Solvent_modal .modal-body #Solvent_CAS')[0].value;
        isEmpty(Charge) ? Charge = "null" : SolventArr[6] = Charge;
        isEmpty(multiplicity) ? multiplicity = "null" : SolventArr[7] = multiplicity;
        isEmpty(structure) ? structure = "null" : SolventArr[8] = structure;
        isEmpty(SMILE_format) ? SMILE_format = "null" : SolventArr[9] = SMILE_format;
        isEmpty(CAS) ? CAS = "null" : SolventArr[10] = CAS;
        <!-- 存储数据 -->
        SolventsArr = SolventsArr.concat(SolventArr);

        <!-- 创建表格一行 -->
        var table = document.getElementById('Solute_components');
        var tbody = table.children[1];
        var ele_num = 0;
        for (var i = 1; i < 6; i = i + 2) {
            if (!isEmpty(SolventArr[i])) {
                ele_num = ele_num + parseInt(SolventArr[i]);
            }
        }
        var tr = document.createElement('tr');
        var td = document.createElement('td');
        var span = document.createElement('span');
        span.appendChild(document.createTextNode(SolventArr.slice(0, 6).join("")));
        td.appendChild(span);
        tr.appendChild(td);
        var td = document.createElement('td');
        var span = document.createElement('span');
        span.appendChild(document.createTextNode(ele_num));
        td.appendChild(span);
        tr.appendChild(td);
        for (var j = 0; j < 2; j++) {
            var td = document.createElement('td');
            var span = document.createElement('span');
            span.appendChild(document.createTextNode(SolventArr[j + 14]));
            td.appendChild(span);
            tr.appendChild(td);
        }
        var td = document.createElement('td');
        var span = document.createElement('span');
        span.appendChild(document.createTextNode(SolventArr[18]));
        td.appendChild(span);
        tr.appendChild(td);
        tbody.appendChild(tr);
    } else {
        alert("溶剂元素添加已满!");
    }
});
$(document).on("click", '#Solvent_Elements_added .modal-footer .btn-primary', function (e) {
    var evt = e || window.event;               //保证兼容性
    var tar = evt.target || evt.srcElement;  //获取触发事件的元素

    var element = $('#Solvent_Elements_added .modal-body #element')[0].value;
    var num = $('#Solvent_Elements_added .modal-body #element_num')[0].value;
    var enough;
    for (var i = 0; i < 6; i = i + 2) {
        if (isEmpty(SolventArr[i])) {
            if (!isEmpty(element) && !isEmpty(num)) {
                SolventArr[i] = element;
                SolventArr[i + 1] = num;
                <!-- 创建表格一行 -->
                var table = document.getElementById('Solute_t_element');
                var tbody = table.children[1];
                var tr = document.createElement('tr');
                for (var j = 0; j < 2; j++) {
                    var td = document.createElement('td');
                    var span = document.createElement('span');
                    span.appendChild(document.createTextNode(SolventArr[i + j]));
                    td.appendChild(span);
                    tr.appendChild(td);
                }
                tbody.appendChild(tr);
            }
            enough = false;
            break;
        } else {
            enough = true;
        }
    }
    if (enough) {
        alert("能添加的元素已满！");
    }
});

/**
 * PBC可选控制
 */
$(document).on("click", '#PBC', function (e) {
    var evt = e || window.event;               //保证兼容性
    var tar = evt.target || evt.srcElement;  //获取触发事件的元素

    if (tar.value === "YES") {
        $('#Lattice_parameters_length').removeAttr("disabled");
        $('#Lattice_parameters_angle').removeAttr("disabled");
        $('#Space_group').removeAttr("disabled");
    } else {
        $('#Lattice_parameters_length').attr("disabled", "");
        $('#Lattice_parameters_angle').attr("disabled", "");
        $('#Space_group').attr("disabled", "");
    }
});

/**
 * 计算对象可选控制
 */
$(document).on("click", '#CalculationObject_select', function (e) {
    var evt = e || window.event;               //保证兼容性
    var tar = evt.target || evt.srcElement;  //获取触发事件的元素

    switch (tar.value) {
        case "晶体":
            $('.Crystal').removeAttr("disabled");
            $('.Slab').attr("disabled", "");
            $('.Solute').attr("disabled", "");
            $('.Solvent').attr("disabled", "");
            $('.Statistics').attr("disabled", "");
            break;
        case "Slab模型":
            $('.Crystal').attr("disabled", "");
            $('.Slab').removeAttr("disabled");
            $('.Solute').attr("disabled", "");
            $('.Solvent').attr("disabled", "");
            $('.Statistics').attr("disabled", "");
            break;
        case "溶质溶剂":
            $('.Crystal').attr("disabled", "");
            $('.Slab').attr("disabled", "");
            $('.Solute').removeAttr("disabled");
            $('.Solvent').removeAttr("disabled");
            $('.Statistics').removeAttr("disabled");
            break;
    }
});

/**
 * 更新原子总数和分子总数
 * @param form_id1
 * @param form_id2
 * @param data
 */
function update_numData(form_id1, form_id2, data) {
    var number_of_molecules = data.split("#").length - 1;
    var number_of_atoms = 0;
    if (data.split("#")[0].split("=")[0] != "") {
        for (var i = 0; i < number_of_molecules; i++) {
            var temp = data.split("#")[i].split("=")[0].split("!");
            for (var j = 1; j < temp.length; j = j + 2) {
                number_of_atoms = number_of_atoms + parseInt(temp[j]);
            }
        }
        document.getElementById(form_id1).value = number_of_molecules;
        document.getElementById(form_id2).value = number_of_atoms;
    } else {
        document.getElementById(form_id1).value = 0;
        document.getElementById(form_id2).value = 0;
    }
}

/**
 * 保存表单数据
 */
function saveQM() {
    var i;
    var k;
    var j;
    var row_num;
//        part1
    var User_and_PBC = document.getElementsByClassName('part1');
    var User_and_PBC_Arr = new Array(6);
    for (i = 0; i < User_and_PBC.length; i++) {
        User_and_PBC_Arr[i] = User_and_PBC.value;
    }
    for (i = 0; i < User_and_PBC_Arr.length; i++) {
        if (isEmpty(User_and_PBC_Arr[i])) {
            User_and_PBC_Arr[i] = "null";
        }
    }
    $("#QM_USER_AND_PBC").val(User_and_PBC_Arr.join("wlcniubi"));
//        part2
    var CalculationObject;
    var CalculationObject_select = $('#CalculationObject_select')[0].value;
    switch (CalculationObject_select) {
        case "晶体":
            CalculationObject = new Array(27);
            var CalculationObject_Crystal = document.getElementsByClassName('Crystal');
            for (i = 0; i < 3; i++) {
                CalculationObject[i] = CalculationObject_Crystal[i].value;
            }
            var Crystal_table = $('#Crystal_table')[0].children[0].children[1];
            row_num = Crystal_table.children.length;
            for (k = 0; k < parseInt(row_num); k++) {
                for (j = 1; j < 3; j++) {
                    CalculationObject[3 + k * 2 + j - 1] = Crystal_table.children[k].children[j].innerHTML;
                }
            }
            for (i = 0; i < 10; i++) {
                CalculationObject[i + 17] = CalculationObject_Crystal[i + 3].value;
            }
            break;
        case "Slab模型":
            break;
        case "溶质溶剂":
            CalculationObject = new Array(68);

            var QM_CalculationObject_Solute = document.getElementsByClassName('Solute');
            var SolutesArrLength = SolutesArr.length;
            for (i = 0; i < (38 - SolutesArrLength) / 19; i++) {
                SolutesArr = SolutesArr.concat(new Array(19));
            }
            for (i = 0; i < SolutesArr.length; i++) {
                CalculationObject[i] = SolutesArr[i];
            }
            for (i = 0; i < 2; i++) {
                CalculationObject[38 + i] = QM_CalculationObject_Solute[i].value;
            }

            var QM_CalculationObject_Solvent = document.getElementsByClassName('Solvent');
            for (i = 0; i < 2; i++) {
                CalculationObject[40 + i] = QM_CalculationObject_Solvent[i].value;
            }
            var SolventsArrLength = SolventsArr.length;
            for (i = 0; i < (22 - SolventsArrLength) / 11; i++) {
                SolventsArr = SolventsArr.concat(new Array(11));
            }
            for (i = 0; i < SolventsArr.length; i++) {
                CalculationObject[42 + i] = SolventsArr[i];
            }
            for (i = 0; i < 2; i++) {
                CalculationObject[64 + i] = QM_CalculationObject_Solvent[i + 2].value;
            }

            var QM_CalculationObject_Statistics = document.getElementsByClassName('Statistics');
            for (i = 0; i < 2; i++) {
                CalculationObject[66 + i] = QM_CalculationObject_Statistics[i].value;
            }
            break;
    }
    for (i = 0; i < CalculationObject.length; i++) {
        if (isEmpty(CalculationObject[i])) {
            CalculationObject[i] = "null";
        }
    }
    $("#QM_Calculation_object").val(CalculationObject.join("wlcniubi"));
//        part3
    var EsqmcArr = new Array(37);
    var Esqmc = document.getElementsByClassName('part3');
    for (i = 0; i < 31; i++) {
        EsqmcArr[i] = Esqmc[i].value;
    }
    var Calculate_base_set_table = document.getElementById('Calculate_base_set_table').children[0].children[1];
    row_num = Calculate_base_set_table.children.length;
    for (k = 0; k < parseInt(row_num); k++) {
        for (j = 1; j < 3; j++) {
            EsqmcArr[31 + 2 * k + j - 1] = temp_str + Calculate_base_set_table.children[k].children[j].innerHTML;
        }
    }
    for (i = 0; i < EsqmcArr.length; i++) {
        if (isEmpty(EsqmcArr[i])) {
            EsqmcArr[i] = "null";
        }
    }
    $("#QM_Electronic_Structure_Quantum_Mechanics_Calculation").val(EsqmcArr.join("wlcniubi"));
//        part4
    var GsesArr = new Array(55);
    var Gses = document.getElementsByClassName('part4');
    for (i = 0; i < 7; i++) {
        GsesArr[i] = Gses[i].value;
    }
    var optimization_table = document.getElementById('optimization_table').children[0].children[1];
    row_num = optimization_table.children.length;
    for (j = 1; j < 8; j++) {
        var temp_str = '';
        for (k = 0; k < parseInt(row_num); k++) {
            temp_str = temp_str + optimization_table.children[k].children[j].innerHTML + ';';
        }
        GsesArr[6 + j] = temp_str;
    }
    for (i = 0; i < 11; i++) {
        GsesArr[14 + i] = Gses[i + 7].value;
    }
    for (i = 0; i < 20; i++) {
        if (i < 4) {
            GsesArr[25] = GsesArr[25] + Gses[i + 18] + ";";
        } else if (i < 10) {
            GsesArr[26] = GsesArr[26] + Gses[i + 18] + ";";
        } else {
            GsesArr[27] = GsesArr[27] + Gses[i + 18] + ";";
        }
    }
    var Vertical_Excited_State_table = document.getElementById('Vertical_Excited_State_table').children[0].children[1];
    row_num = Vertical_Excited_State_table.children.length;
    for (k = 0; k < parseInt(row_num); k++) {
        for (j = 1; j < 3; j++) {
            GsesArr[28 + k * 2 + j - 1] = Vertical_Excited_State_table.children[k].children[j].innerHTML;
        }
    }
    var other_table = document.getElementById('other_table').children[0].children[1];
    row_num = other_table.children.length;
    for (j = 1; j < 2; j++) {
        var temp_str = '';
        for (k = 0; k < parseInt(row_num); k++) {
            temp_str = temp_str + other_table.children[k].children[j].innerHTML + ";";
        }
        GsesArr[34] = temp_str;
    }
    for (i = 0; i < GsesArr.length; i++) {
        if (isEmpty(GsesArr[i])) {
            GsesArr[i] = "null";
        }
    }
    $("#QM_Ground_state_excited_state").val(GsesArr.join("wlcniubi"));

    document.getElementById("QM_submit").click();
}

/**
 * 高斯文件上传处理
 */
$(document).on("click", '#QM_gaussFiles_modal .modal-footer .btn-primary', function (e) {
    //files_process
    var gaussFiles_log = $('#gaussFiles_log')[0];
    var logFileLength = gaussFiles_log.files.length;
    var gaussFiles_dat = $('#gaussFiles_dat')[0].files.length > 0 ? $('#gaussFiles_dat')[0].files[0] : new File([], "");
    if (logFileLength > 0) {
        for (var i = 0; i < logFileLength; i++) {
            var fileForm = new FormData();
            fileForm.append("log_file", gaussFiles_log.files[i]);
            fileForm.append("dat_file", gaussFiles_dat);
            $.ajax({
                url: '../compute_part/QM_gaussFiles_process',
                type: 'POST',
                data: fileForm,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    var num = parseInt(i) + 1;
                    if (returndata === "success") {
                        notyf.confirm('您上传的第' + num + '个高斯文件已经被成功处理！');
                    }else {
                        notyf.alert('您上传的第' + num + '个高斯文件存在错误终止情况！');
                    }
                },
                error: function (returndata) {
                    var num = parseInt(i) + 1;
                    notyf.alert('您上传的第' + num + '个高斯文件处理失败！请联系管理员！');
                }
            });
        }
    } else {
        notyf.alert("请选择上传文件！");
    }
});

/**
 * GEBF文件上传处理
 */
$(document).on("click", '#QM_gebfFiles_modal .modal-footer .btn-primary', function (e) {
    //files_process
    var gebfFfiles_Groups = $('.gebfFfiles_Group');
    for (var i = 0; i < gebfFfiles_Groups.length; i++) {
        var keysFile = $('#' + gebfFfiles_Groups[i].id + ' #gebfFiles_keys')[0].files;
        var chaFile = $('#' + gebfFfiles_Groups[i].id + ' #gebfFiles_cha')[0].files;
        var txtFile = $('#' + gebfFfiles_Groups[i].id + ' #gebfFiles_txt')[0].files;
        var logFile = $('#' + gebfFfiles_Groups[i].id + ' #gebfFiles_log')[0].files;
        var frgFile = $('#' + gebfFfiles_Groups[i].id + ' #gebfFiles_frg')[0].files;
        if (keysFile.length > 0 && chaFile.length > 0 && txtFile.length > 0 && frgFile.length > 0) {
            var gebfFiles_log = logFile.length > 0 ? logFile[0] : new File([], "");
            var fileForm = new FormData();
            fileForm.append("keys_file", keysFile[0]);
            fileForm.append("cha_file", chaFile[0]);
            fileForm.append("txt_file", txtFile[0]);
            fileForm.append("log_file", gebfFiles_log);
            fileForm.append("frg_file", frgFile[0]);
            $.ajax({
                url: 'QM_gebfFiles_process',
                type: 'POST',
                data: fileForm,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    if (returndata === "success") {
                        var num = parseInt(i) + 1;
                        notyf.confirm('您上传的第' + num + '组gebf文件已经被成功处理！');
                    }
                },
                error: function (returndata) {
                    var num = parseInt(i) + 1;
                    notyf.alert('您上传的第' + num + '组gebf文件处理失败！请联系管理员！');
                }
            });
        } else {
            var num = i + 1;
            notyf.alert('您上传的第' + num + '组gebf文件上传文件不全！');
        }
    }
});

/**
 * Dmol3文件上传处理
 */
$(document).on("click", '#QM_dmol3Files_modal .modal-footer .btn-primary', function (e) {

    // 文件及表元素获取
    var cif_files = $('#dmol3Files_cif')[0].files;
    var outmol_files = $('#dmol3Files_outmol')[0].files;
    var dosOutmol_files = $('#dmol3Files_dosOutmol')[0].files;
    var bandStrOutmol_files = $('#dmol3Files_bandStrOutmol')[0].files;

    //取最大文件长度
    var file_length = cif_files.length;
    if (outmol_files.length > file_length) {file_length=outmol_files.length}
    if (dosOutmol_files.length > file_length) {file_length=dosOutmol_files.length}
    if (bandStrOutmol_files.length > file_length) {file_length=bandStrOutmol_files.length}

    // 文件解析
    for (var i = 0; i < file_length; i++) {
        if (outmol_files.length > 0) {
            var dmol3Files_cif = isEmpty(cif_files[i])?new File([], ""):cif_files[i];
            var dmol3Files_outmol = isEmpty(outmol_files[i])?new File([], ""):outmol_files[i];
            var dmol3Files_dosOutmol = isEmpty(dosOutmol_files[i])?new File([], ""):dosOutmol_files[i];
            var dmol3Files_bandStrOutmol = isEmpty(bandStrOutmol_files[i])?new File([], ""):bandStrOutmol_files[i];
            var fileForm = new FormData();
            fileForm.append("cif_file", dmol3Files_cif);
            fileForm.append("outmol_file", dmol3Files_outmol);
            fileForm.append("dosOutmol_file", dmol3Files_dosOutmol);
            fileForm.append("bandStrOutmol_file", dmol3Files_bandStrOutmol);
            fileForm.append("calculateObject", $('#dmol3Files_calculateObject')[0].value);
            $.ajax({
                url: 'QM_dmol3Files_process',
                type: 'POST',
                data: fileForm,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    if (returndata === "success") {
                        $('.dmol3Files-process')[i].innerHTML = '<i class="fa fa-check fa-fw" style="color: #20a53a;"></i>';
                        var num = i + 1;
                        notyf.confirm('您上传的第' + num + '组Dmol3文件已经被成功处理！');
                    } else {
                        $('.dmol3Files-process')[i].innerHTML = '<i class="fa fa-remove fa-fw" style="color: #D74A3C;"></i>';
                    }
                },
                error: function (returndata) {
                    var num = parseInt(i) + 1;
                    $('.dmol3Files-process')[i].innerHTML = '<i class="fa fa-remove fa-fw" style="color: #D74A3C;"></i>';
                    notyf.alert('您上传的第' + num + '组Dmol3文件处理失败！请联系管理员！');
                }
            });
        } else {
            var num = i + 1;
            notyf.alert('您上传的第' + num + '组Dmol3文件中outmol类型文件没有上传！');
        }
    }
});
$(document).on("change", '#dmol3Files_cif', function (e) {
    var evt=e||window.event;               //保证兼容性
    var tar=evt.target||evt.srcElement;  //获取触发事件的元素

    updataDmol3Table()
});
$(document).on("change", '#dmol3Files_outmol', function (e) {
    var evt=e||window.event;               //保证兼容性
    var tar=evt.target||evt.srcElement;  //获取触发事件的元素

    updataDmol3Table()
});
$(document).on("change", '#dmol3Files_dosOutmol', function (e) {
    var evt=e||window.event;               //保证兼容性
    var tar=evt.target||evt.srcElement;  //获取触发事件的元素

    updataDmol3Table()
});
$(document).on("change", '#dmol3Files_bandStrOutmol', function (e) {
    var evt=e||window.event;               //保证兼容性
    var tar=evt.target||evt.srcElement;  //获取触发事件的元素

    updataDmol3Table()
});
function updataDmol3Table() {
    // 文件及表元素获取
    var cif_files = $('#dmol3Files_cif')[0].files;
    var outmol_files = $('#dmol3Files_outmol')[0].files;
    var dosOutmol_files = $('#dmol3Files_dosOutmol')[0].files;
    var bandStrOutmol_files = $('#dmol3Files_bandStrOutmol')[0].files;
    var tbody = $('#QM_dmol3Files-table .QM_dmol3Files-table-body .table tbody');
    tbody.empty();
    tbody = tbody[0];

    //取最大文件长度
    var file_length = cif_files.length;
    if (outmol_files.length > file_length) {file_length=outmol_files.length}
    if (dosOutmol_files.length > file_length) {file_length=dosOutmol_files.length}
    if (bandStrOutmol_files.length > file_length) {file_length=bandStrOutmol_files.length}

    for (var i = 0; i < file_length; i++) {
        var cif_name = isEmpty(cif_files[i])?'':cif_files[i].name;
        var outmol_name = isEmpty(outmol_files[i])?'':outmol_files[i].name;
        var dosOutmol_name = isEmpty(dosOutmol_files[i])?'':dosOutmol_files[i].name;
        var bandStrOutmol_name = isEmpty(bandStrOutmol_files[i])?'':bandStrOutmol_files[i].name;
        var tr_node = $('<tr> ' +
            '<td class="dmol3Files-index">'+i+'</td> ' +
            '<td class="dmol3Files-cif">'+cif_name+'</td> ' +
            '<td class="dmol3Files-outmol">'+outmol_name+'</td> ' +
            '<td class="dmol3Files-dosOutmol">'+dosOutmol_name+'</td> ' +
            '<td class="dmol3Files-bandStrOutmol">'+bandStrOutmol_name+'</td> ' +
            '<td class="dmol3Files-process"><i class="fa fa-spinner fa-fw" style="color: #06F;"></i></td> ' +
            '</tr>')[0];
        tbody.appendChild(tr_node);
    }
}

/**
 * CASTEP文件上传处理
 */
$(document).on("click", '#QM_castepFiles_modal .modal-footer .btn-primary', function (e) {
    //files_process
    var castepFiles_Group = $('.castepFiles_Group');
    for (var i = 0; i < castepFiles_Group.length; i++) {
        var cifFile = $('#' + castepFiles_Group[i].id + ' #castepFiles_cif')[0].files;
        var castepFile = $('#' + castepFiles_Group[i].id + ' #castepFiles_castep')[0].files;
        var dosCastepFile = $('#' + castepFiles_Group[i].id + ' #castepFiles_dosCastep')[0].files;
        var bandStrCastepFile = $('#' + castepFiles_Group[i].id + ' #castepFiles_bandStrCastep')[0].files;
        if (castepFile.length > 0) {
            var castepFiles_cif = cifFile.length > 0 ? cifFile[0] : new File([], "");
            var castepFiles_dosCastep = dosCastepFile.length > 0 ? dosCastepFile[0] : new File([], "");
            var castepFiles_bandStrCastep = bandStrCastepFile.length > 0 ? bandStrCastepFile[0] : new File([], "");
            var fileForm = new FormData();
            fileForm.append("cif_file", castepFiles_cif);
            fileForm.append("castep_file", castepFile[0]);
            fileForm.append("dosCastep_file", castepFiles_dosCastep);
            fileForm.append("bandStrCastep_file", castepFiles_bandStrCastep);
            fileForm.append("calculateObject", $('#' + castepFiles_Group[i].id + ' #castepFiles_calculateObject')[0].value);
            $.ajax({
                url: 'QM_castepFiles_process',
                type: 'POST',
                data: fileForm,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    var num = parseInt(i) + 1;
                    if (returndata === "success") {
                        notyf.confirm('您上传的第' + num + '组Castep文件已经被成功处理！');
                    } else {
                        notyf.alert('您上传的第' + num + '组Castep文件类型不匹配');
                    }
                },
                error: function (returndata) {
                    var num = parseInt(i) + 1;
                    notyf.alert('您上传的第' + num + '组Castep文件处理失败！请联系管理员！');
                }
            });
        } else {
            var num = parseInt(i) + 1;
            notyf.alert('您上传的第' + num + '组Castep文件中castep类型文件没有上传！');
        }
    }
});

/**
 * VASP文件上传处理
 */
$(document).on("click", '#QM_vaspFiles_modal .modal-footer .btn-primary', function (e) {
    //files_process
    var vaspFiles_Group = $('.vaspFiles_Group');
    for (var i = 0; i < vaspFiles_Group.length; i++) {
        var incarFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_INCAR')[0].files;
        var poscarFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_POSCAR')[0].files;
        var potcarFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_POTCAR')[0].files;
        var poscarcifFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_POSCARcif')[0].files;
        var kpointsFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_KPOINTS')[0].files;
        var contcarFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_CONTCAR')[0].files;
        var outcarFile = $('#' + vaspFiles_Group[i].id + ' #vaspFiles_OUTCAR')[0].files;
        if (outcarFile.length > 0 && contcarFile.length > 0) {
            var vaspFiles_incar = incarFile.length > 0 ? incarFile[0] : new File([], "");
            var vaspFiles_poscar = poscarFile.length > 0 ? poscarFile[0] : new File([], "");
            var vaspFiles_potcar = potcarFile.length > 0 ? potcarFile[0] : new File([], "");
            var vaspFiles_cif = poscarcifFile.length > 0 ? poscarcifFile[0] : new File([], "");
            var vaspFiles_kpoints = kpointsFile.length > 0 ? kpointsFile[0] : new File([], "");
            var fileForm = new FormData();
            fileForm.append("incar_file", vaspFiles_incar);
            fileForm.append("poscar_file", vaspFiles_poscar);
            fileForm.append("potcar_file", vaspFiles_potcar);
            fileForm.append("cif_file", vaspFiles_cif);
            fileForm.append("kpoints_file", vaspFiles_kpoints);
            fileForm.append("contcar_file", contcarFile[0]);
            fileForm.append("outcar_file", outcarFile[0]);
            fileForm.append("calculateObject", $('#' + vaspFiles_Group[i].id + ' #vaspFiles_calculateObject')[0].value);
            $.ajax({
                url: 'QM_vaspFiles_process',
                type: 'POST',
                data: fileForm,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    var num = parseInt(i) + 1;
                    if (returndata === "success") {
                        notyf.confirm('您上传的第' + num + '组VASP文件已经被成功处理！');
                    } else {
                        notyf.alert('您上传的第' + num + '组VASP文件类型不匹配');
                    }
                },
                error: function (returndata) {
                    var num = parseInt(i) + 1;
                    notyf.alert('您上传的第' + num + '组VASP文件处理失败！请联系管理员！');
                }
            });
        } else {
            var num = parseInt(i) + 1;
            notyf.alert('您上传的第' + num + '组VASP文件中必要类型文件没有上传！');
        }
    }
});